package com.amat0urheu.dao;


import com.amat0urheu.pojo.CloudPojo.Flavor;
import com.amat0urheu.pojo.CloudPojo.VMservice;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VmMapper {

    @Select("select * from mc_vm  ")
    List<Flavor> getVms(String openstackIP);
    int refreshNewVMs(List<VMservice> VMs);
    @Update("update mc_vm set noVNC=#{experimentVm.noVNC} ,status=#{experimentVm.status} where vmID=#{experimentVm.vmID} and( noVNC is null or noVNC!=#{experimentVm.noVNC} or status!=#{experimentVm.status})   ")
    Integer updateVmyVMId(@Param("experimentVm") VMservice experimentVm);

    @Select("select openstackIP from mc_vm where vmID=#{vmID}")
    String getOpenstackIPofVm(String vmID);
@Update("update mc_vm set status=#{action} where  vmID=#{vmID} ")
    int updateStatusByVmid(String vmID,String action);

@Select("select * from mc_vm where vmID=#{vmID} ")
    VMservice getRaceVms(String vmID);
    @Update("update mc_vm set userStatus='已连接' where  vmName=#{vmName} and user=#{name}")
    Integer updatevmOfUser(String vmName, String name);

    @Update("update mc_vm set  team=#{teamName} where proxyNum=#{proxy}")
    Integer submitApplyRaceVm(Integer proxy,String teamName, String  race);

    @Select("select proxyNum  from mc_vm where team is null and   race=#{race}  and type NOT LIKE '%client%' and deadTime > CURRENT_TIMESTAMP group by proxyNum limit 1  ")
    Integer getFreeProxy(String race);
    @Select("select count(*) from mc_vm where team=#{teamName} and race=#{race} ")
    Integer getVMCountOfRace(String race, String teamName);
    @Select("select count(*) from mc_vm where  user=#{name} and type like '%client%'  and race=#{race}")
    Integer getClientVMCountOfUser(String race, String name);
    @Update("update mc_vm set  user=#{name}  where proxyNum=#{proxy} and race=#{race}")
    Integer getClientVMOfUser(String race, String name,Integer proxy);
    @Select("select proxyNum  from mc_vm where user is null and   race=#{race}  and  type like '%client%' and deadTime > CURRENT_TIMESTAMP group by proxyNum limit 1  ")
    Integer getFreeClientProxy(String race);

    @Select("select vmID  from mc_vm where team=#{teanName} ")
    List<String> getVmIdsofTeam(String teanName);
    @Update("update mc_race_flag set  team=#{teamName}  where vm=#{vmId}")
    void setFlagToTeam(String vmId,String teamName,Integer rid);
@Delete("delete from mc_vm where  vmId=#{vmId}")
    int deleteVm(String vmID);


/*@Insert("insert into mc_experiment_vm  ")
    Integer inserIntoVm(@Param("experimentVm") ExperimentVm experimentVm);*/
}
